package com.ruoyi.loan.loan.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.LoanSignatureVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loan.loan.domain.TbLoanSignature;
import com.ruoyi.loan.loan.service.ITbLoanSignatureService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 借款签章Controller
 * 
 * @author 杰少
 * @date 2023-01-14
 */
@Slf4j
@Api("signature-server")
@RestController
@RequestMapping("/signature")
public class TbLoanSignatureController extends BaseController
{
    @Autowired
    private ITbLoanSignatureService tbLoanSignatureService;

    /**
     * 查询借款签章列表
     */
    @RequiresPermissions("loan:signature:list")
    @GetMapping("/list")
    public TableDataInfo list(TbLoanSignature tbLoanSignature)
    {
        startPage();
        List<TbLoanSignature> list = tbLoanSignatureService.selectTbLoanSignatureList(tbLoanSignature);
        return getDataTable(list);
    }

    /**
     * 导出借款签章列表
     */
    @RequiresPermissions("loan:signature:export")
    @Log(title = "借款签章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLoanSignature tbLoanSignature)
    {
        List<TbLoanSignature> list = tbLoanSignatureService.selectTbLoanSignatureList(tbLoanSignature);
        ExcelUtil<TbLoanSignature> util = new ExcelUtil<TbLoanSignature>(TbLoanSignature.class);
        util.exportExcel(response, list, "借款签章数据");
    }

    /**
     * 获取借款签章详细信息
     */
    @RequiresPermissions("loan:signature:query")
    @GetMapping(value = "/{loanSignatureId}")
    public AjaxResult getInfo(@PathVariable("loanSignatureId") Long loanSignatureId)
    {
        return success(tbLoanSignatureService.selectTbLoanSignatureByLoanSignatureId(loanSignatureId));
    }

    /**
     * 新增借款签章
     */
    @RequiresPermissions("loan:signature:add")
    @Log(title = "借款签章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LoanSignatureVo tbLoanSignature)
    {
        return toAjax(tbLoanSignatureService.insertTbLoanSignature(tbLoanSignature));
    }

    /**
     * 修改借款签章
     */
    @RequiresPermissions("loan:signature:edit")
    @Log(title = "借款签章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LoanSignatureVo tbLoanSignature)
    {
        return toAjax(tbLoanSignatureService.updateTbLoanSignature(tbLoanSignature));
    }

    /**
     * 删除借款签章
     */
    @RequiresPermissions("loan:signature:remove")
    @Log(title = "借款签章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{loanSignatureIds}")
    public AjaxResult remove(@PathVariable Long[] loanSignatureIds)
    {
        return toAjax(tbLoanSignatureService.deleteTbLoanSignatureByLoanSignatureIds(loanSignatureIds));
    }
}
